﻿#include "searchhotelcontent.h"
#include "ui_searchhotelcontent.h"

SearchHotelContent::SearchHotelContent(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SearchHotelContent)
{
    ui->setupUi(this);

    m_hotelInfo = GlobalVars::g_localHotel;

    initWindowsUnits();
}

SearchHotelContent::~SearchHotelContent()
{
    delete ui;
}

void SearchHotelContent::initWindowsUnits()
{
    m_hotelID = m_hotelInfo.getHotel();
    QString mark;
    ui->pb_name->setText(m_hotelInfo.getName());
    ui->lb_star->setText(m_hotelInfo.getStar());
    ui->lb_location->setText(m_hotelInfo.getLocation());
    ui->lb_consumeCount->setText(QString::number(m_hotelInfo.getCommentCount()) + " 消费");
    ui->lb_price->setText(QString::number(m_hotelInfo.getLowPrice()));
    if (m_hotelInfo.getMark().toDouble() > 4.5)
    {
        mark = m_hotelInfo.getMark() + "分 很好";
    }
    else if(m_hotelInfo.getMark().toDouble() <= 4)
    {
        mark = m_hotelInfo.getMark() + "分 不错";
    }
    else
    {
        mark = m_hotelInfo.getMark() + "分  好";
    }
    ui->lb_mark->setText(mark);

    QStringList server = m_hotelInfo.getServer().split(",");
    qDebug() << "server = " << server << server.size();
    if (server.size() == 1)
    {
        if (server.at(0).isEmpty())
        {
            return;
        }
    }
    switch (server.size())
    {
        default:
        case 4:
            ui->lb_server4->setText(server.at(3));
            ui->lb_icon4->setStyleSheet(GlobalVars::g_serverStyleSheet[server.at(3)]);
        case 3:
            ui->lb_server3->setText(server.at(2));
            ui->lb_icon3->setStyleSheet(GlobalVars::g_serverStyleSheet[server.at(2)]);
        case 2:
            ui->lb_server2->setText(server.at(1));
            ui->lb_icon2->setStyleSheet(GlobalVars::g_serverStyleSheet[server.at(1)]);
        case 1:
            ui->lb_server1->setText(server.at(0));
            ui->lb_icon1->setStyleSheet(GlobalVars::g_serverStyleSheet[server.at(0)]);
        case 0: break;
    }
}

const QString& SearchHotelContent::getHotelID()
{
    return m_hotelID;
}


void SearchHotelContent::setCount(int count)
{
    ui->lb_number->setText(QString::number(count));
}

void SearchHotelContent::setImage(const QImage& image)
{
    ui->lb_image->setPixmap(QPixmap::fromImage(image.scaled(200,125)));
}

HotelInfo SearchHotelContent::getHotelInfo()
{
    return m_hotelInfo;
}
void SearchHotelContent::on_pb_watchDetails_clicked()
{
    emit signalGainHotelDetails(m_hotelInfo.getHotel());            /// 发送信号 - 获取hotelDetails
}

void SearchHotelContent::on_pb_name_clicked()
{
    on_pb_watchDetails_clicked();
}

void SearchHotelContent::on_pb_watchComment_clicked()
{
    on_pb_watchDetails_clicked();
    emit signalWatchComment();
}
